package com.leo.stopwatch;

/*Copyright (c) 2010-2012, Daniel Bostwick

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
3. Neither the name of Daniel Bostwick nor the names
   of its contributors may be used to endorse or promote products derived
   from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.*/
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

public class menu extends Activity{
	private static final int menu1=0;
	private static final int menu2=1; 
	private static final int menu3=2;
	private Button a,b;
	@Override
	        public void onCreate(Bundle savedInstanceState) {
	               super.onCreate(savedInstanceState);
	               requestWindowFeature(Window.FEATURE_NO_TITLE);
	             setContentView(R.layout.main);
	             
	             AdView adView=new AdView(this,AdSize.BANNER, "publish id");
	             LinearLayout layout = (LinearLayout)findViewById(R.id.AdLayout);
	             layout.addView(adView);
	             adView.loadAd(new AdRequest());
	             
	             a = (Button) findViewById(R.id.a);
	             b = (Button) findViewById(R.id.b);
	           
	              //*button start*/
	             
	             a.setOnClickListener(new OnClickListener()
	        		{
						@Override
						public void onClick(View v)
						{
							Intent intenta = new Intent();
							intenta.setClass(menu.this,StopwatchActivity.class);
							startActivity(intenta);						
						}		
	        		});//*button end*/
	             //*button start*/
	             b.setOnClickListener(new OnClickListener()
	        		{
						@Override
						public void onClick(View v)
						{
							Intent intentb = new Intent();
							intentb.setClass(menu.this,Stopwatchcount.class);
							startActivity(intentb);						
						}		
	        		});//*button end*/
	          
	}//*onCreate end*/
	  public boolean onCreateOptionsMenu(Menu menu){
	    	super.onCreateOptionsMenu(menu);
	    	menu.add(0,menu1,0,(R.string.about)).setIcon(R.drawable.info);
	    	menu.add(0,menu2,0,(R.string.exit)).setIcon(R.drawable.exit);menu.add(0, menu3, 0, (R.string.app)).setIcon(R.drawable.app);
	    	return true;
	    }
	    public boolean onOptionsItemSelected(MenuItem item){
	     switch(item.getItemId())
	     {
	     case menu1:
	    	 showAlertDialog("CEO/作者:Leo\nComments/評論:pcschoolleo@gmail.com\nIcons/圖示:www.iconfinder.com\n"+"original source:https://github.com/bostwick/android-stopwatch\n"+
	    			 "original copyright:Daniel Bostwick");
	    	 return true;
	     case menu2:
	    	 finish();
	    	 return true;   case menu3:
					Intent intenta = new Intent(Intent.ACTION_VIEW);
					intenta.setData(Uri.parse("market://search?q=pcschoolleo"));
					startActivity(intenta);
					return true; 
	     }
	     return false;
	    }
	    private void showAlertDialog(String message){
	    	new AlertDialog.Builder(this)
	    	.setMessage(message)
	    	.setPositiveButton("ok",null)
	    	.show();
	    }
}
